﻿; $(function () {
    $("#toolbar").ligerToolBar({
        items: [{
            text: '添加',
            icon: '',
            id: 'btnSave',
            click: function (parameters) {
                location.href = "/Content/Edit";
            }
        },
            {
                text: '编辑',
                icon: '',
                id: 'btnEdit',
                click: function (parameters) {
                    var rows = manager.getSelectedRows();
                    if (rows && rows.length == 1) {
                        var row = manager.getSelectedRow();
                        if (row && row.ContentId != "") {
                            //if (row.IsChecked == 1) {
                            //} else {
                            location.href = "/Content/Edit?Id=" + row.ContentId;
                            // }
                        } else {
                            $.ligerDialog.warn('请选择单条记录');
                        }
                    } else {
                        $.ligerDialog.warn('请选择单条记录');
                    }
                }
            },
            {
                text: '删除',
                icon: '',
                id: 'btnDelete',
                click: function (parameters) {

                    var rows = manager.getSelectedRows();
                    if (rows && rows.length > 0) {
                        var ids = new Array();
                        $.each(rows, function () {
                            ids.push(this.ContentId);
                        });
                        $.ajax({
                            url: '/Content/DeleteContents',
                            dataType: 'json',
                            type: 'post',
                            data: { ids: ids.join(",") },
                            traditional: true,
                            success: function (callback) {
                                if (callback) {
                                    $.ligerDialog.alert('删除成功', function (yes) {
                                        manager.loadData();
                                    });
                                }
                                else {
                                    $.ligerDialog.error('删除失败');
                                }
                            },
                            error: function (ex) {
                                $.ligerDialog.error('删除失败');
                            }
                        });
                    } else {

                    }


                }
            }]
    });


    var manager = $("#grid").ligerGrid({
        columns: [
            { display: 'ID', name: 'ContentId', isSort: false, width: 40, align: 'left',hide:true },
            {
                display: '标题',
                align: 'left',
                width: 500,
                minWidth: 100,
                name: 'Title'
            },
            { display: '发布者', name: 'AdminUserName', isSort: false, width: 250, align: 'left' },
            { display: '发布时间', name: 'ReleaseDate', isSort: false, width: 100, align: 'left' }],
        width: '99.85%',
        height:'100%',
        heightDiff:-20,
        pageSizeOptions:[5, 10, 15, 20],
        pageSize: 15,
        alternatingRow:false,
        url:"/Content/Contents",
        headerRowHeight:26,
        checkbox: true,
        autoCheckChildren: false,
        dataAction: "server"
    });
});